//
//  NoNetWorkView.m
//  EBusiness_iOS
//
//  Created by uplooking on 2016/12/9.
//  Copyright © 2016年 chenrenlong. All rights reserved.
//

#import "NoNetWorkView.h"

@interface NoNetWorkView ()
{
    
}
@end

@implementation NoNetWorkView

-(instancetype)initWithFrame:(CGRect)frame{
    
    self=[super initWithFrame:frame];
    
    if (self) {
        
        [self initView];
        [self btnAction:nil];
    }
    
    return self;
}


-(void)initView{
    
    self.backgroundColor = HexRGBA(0xffffff, 1);
    
    UIImageView *imageView=[[UIImageView alloc]init];
    [imageView setImage:[UIImage imageNamed:@"img_no_network"]];
    [self addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self).offset(-110* kAutoScanleX);
        make.centerX.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(110* kAutoScanleX, 110* kAutoScanleX));
    }];
    
    
    
    UILabel * topLabel=[[UILabel alloc]init];
    [topLabel setTextAlignment:NSTextAlignmentCenter];
    [topLabel setTextColor:RGBACOLOR(112, 115, 118, 1)];
    [topLabel setNumberOfLines:0];
    [topLabel setText:@"网络请求失败"];
    [topLabel setFont:[UIFont systemFontOfSize:18 * kAutoScanleX]];
    [self addSubview:topLabel];
    [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).offset(10 * kAutoScanleX);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(20 * kAutoScanleX);
    }];
    
    
    UILabel * midLabel=[[UILabel alloc]init];
    [midLabel setTextAlignment:NSTextAlignmentCenter];
    [midLabel setTextColor:RGBACOLOR(181, 181, 181, 1)];
    [midLabel setNumberOfLines:0];
    [midLabel setText:@"请检查您的网络"];
    [midLabel setFont:[UIFont systemFontOfSize:15 * kAutoScanleX]];
    [self addSubview:midLabel];
    [midLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topLabel.mas_bottom).offset(10 * kAutoScanleX);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(20 * kAutoScanleX);
    }];
    
    UILabel * bomLabel = [[UILabel alloc]init];
    [bomLabel setTextAlignment:NSTextAlignmentCenter];
    [bomLabel setTextColor:RGBACOLOR(181, 181, 181, 1)];
    [bomLabel setNumberOfLines:0];
    [bomLabel setText:@"重新加载吧"];
    [bomLabel setFont:[UIFont systemFontOfSize:15 * kAutoScanleX]];
    [self addSubview:bomLabel];
    [bomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(midLabel.mas_bottom);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(20);
    }];
    
    
    UIButton *btn=[[UIButton alloc]init];
    [btn setAdjustsImageWhenHighlighted:NO];
    [btn setImage:[UIImage imageNamed:@"btn_reload"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bomLabel.mas_bottom).offset(20 * kAutoScanleX);
        make.centerX.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(110 * kAutoScanleX, 33 * kAutoScanleX));
    }];
    
    
}

- (void)netWork{
    
    if(UserCenterHelper.checkNetWork){
        
        [self showHint:@"网络请求失败，请检查您的网络"];
        
    }else{
        
        if (self.blockNetWork) {
            
           [self removeFromSuperview];
           self.blockNetWork();
        }
    }
    
}

- (void)btnAction:(UIButton *)sender{
    
    [self netWork];
}


@end
